<?php

/**
 * This is the model class for table "ecom_products".
 *
 * The followings are the available columns in table 'ecom_products':
 * @property string $products_id
 * @property string $products_products_category_id
 * @property string $products_code
 * @property string $products_name
 * @property string $products_description
 * @property string $products_price
 * @property string $products_sponsor_bonus_value
 */
class ecom_products extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @return ecom_products the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'ecom_products';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
                array('products_products_category_id, products_code, products_name, products_price, products_sponsor_bonus_value', 'required'),
                array('products_products_category_id, products_price, products_sponsor_bonus_value', 'length', 'max' => 10),
                array('products_code', 'length', 'max' => 25),
                array('products_name', 'length', 'max' => 100),
                array('products_bv,products_description,products_hpp,products_profit_share,products_bonus_value', 'safe'),
                // The following rule is used by search().
                // Please remove those attributes that should not be searched.
                array('products_id, products_products_category_id, products_code, products_name, products_description, products_price, products_sponsor_bonus_value', 'safe', 'on' => 'search'),
                array(
                        'products_images', 'file', 'on' => 'insert',
                        'allowEmpty' => true,
                        'types' => 'jpg, gif, png, pdf',
                        'maxSize' => 1024 * 1024 * 1,
                        'tooLarge' => 'Ukuran file melebihi batas yang ditentukan',
                ),
                array(
                        'products_images', 'file', 'on' => 'update',
                        'allowEmpty' => true,
                        'types' => 'jpg, gif, png, pdf',
                        'maxSize' => 1024 * 1024 * 1,
                        'tooLarge' => 'Ukuran file melebihi batas yang ditentukan',
                ),
                array('products_images','unsafe'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
                'rel_products_to_products_category' => array(self::BELONGS_TO, 'ecom_products_category', 'products_products_category_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
                'products_id' => 'Products',
                'products_products_category_id' => 'Products Category',
                'products_code' => 'Products Code',
                'products_name' => 'Products Name',
                'products_description' => 'Products Description',
                'products_price' => 'Products Price',
                'products_sponsor_bonus_value' => 'Direct Royalty Bonus',
                'products_hpp' => 'HPP Product',
                'products_profit_share' => 'Profit Sharing for Member',
                'products_images' => 'Image',
                'products_bv' => 'Nilai BV',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('products_id', $this->products_id, true);
        $criteria->compare('products_products_category_id', $this->products_products_category_id, true);
        $criteria->compare('products_code', $this->products_code, true);
        $criteria->compare('products_name', $this->products_name, true);
        $criteria->compare('products_description', $this->products_description, true);
        $criteria->compare('products_price', $this->products_price, true);
        $criteria->compare('products_bv', $this->products_bv, true);
        $criteria->compare('products_sponsor_bonus_value', $this->products_sponsor_bonus_value, true);

        return new CActiveDataProvider($this, array(
                        'criteria' => $criteria,
        ));
    }

}